**********************************************************************
*
* Economic hardship triggers identification with disadvantaged minorities
* Simonovits and Kezdi
* Analysis code
*  input: identification_workfile.dta
*
* 2015
*
**********************************************************************

clear

**********************************************************************
**********************************************************************
* PART I
* ECONOMIC HARDSHIP TRIGGERS ROMA IDENTIFICATION

global HARDSHIP hardship
global DESCENT descent_roma
*global DESCENT descent_roma_narrow
global CONTROLS age_ym womother wofather newaddress hsize inschool child partner_roma partner_nonroma partner_unknown
global DCONTROLS Dage_ym Dwomother Dwofather Dnewaddress Dhsize Dinschool Dchild Dpartner_roma Dpartner_nonroma Dpartner_unknown



use identification_workfile
drop if wave=="a"
*****************************
** UNBALANCED SAMPLE
** drop if missing key variable
drop if $HARDSHIP==.
drop if $DESCENT==.
keep if roma!=.
** create variable for missing controls
gen missing_controls=0
foreach x of varlist $CONTROLS {
	replace missing_controls=1 if `x'==.
}
** create wave FE 
encode wave, gen(wavenum)
qui tab wave, gen(W)
rename W4 W6
rename W3 W5
rename W2 W4
rename W1 W2
sum W*
xtset sorszam wavenum
xtdes
save temp_unbal,replace

*****************************
** BALANCED SAMPLE
egen panel_count=count(wavenum), by(sorszam)
keep if panel_count==4
** drop if missing controls
*keep if missing_controls==0

xtset sorszam wavenum
xtdes

qui foreach x in roma $HARDSHIP $CONTROLS {
	cap gen D`x'=d.`x'
}
save temp_bal,replace

*************************************************************************
** SUMMARY STATISTICS
use temp_bal,replace
sum roma $HARDSHIP $CONTROLS [w=suly] if $DESCENT==1, separator(0)
 sum Droma D$HARDSHIP $DCONTROLS [w=suly] if $DESCENT==1, separator(0)
 xtsum roma $HARDSHIP $CONTROLS if $DESCENT==1
sum roma $HARDSHIP $CONTROLS [w=suly] if $DESCENT==0, separator(0)
 sum Droma D$HARDSHIP $DCONTROLS [w=suly] if $DESCENT==0, separator(0)
 xtsum roma $HARDSHIP $CONTROLS if $DESCENT==0

*************************************************************************
** MAIN RESULTS
use temp_bal,replace
sum roma $HARDSHIP $CONTROLS [w=suly] if $DESCENT==1, separator(0)
sum Droma D$HARDSHIP $DCONTROLS [w=suly] if $DESCENT==1, separator(0)
xtsum roma if $DESCENT==1
xtsum roma if $DESCENT==1 & missing_controls==0
** FE & FD REGRESSIONS
qui xtreg roma $HARDSHIP D$HARDSHIP if $DESCENT==1 [w=suly], fe cluster(sorszam)
  qui outreg using FEFD, se bdec(3) starlev(5) replace ctitle("","DELETE")
qui xtreg roma $HARDSHIP W4 W5 W6 if $DESCENT==1 [w=suly], fe cluster(sorszam)
  qui outreg using FEFD, se bdec(3) starlev(5) merge ctitle("","FE")
qui xtreg roma $HARDSHIP W4 W5 W6 $CONTROLS if $DESCENT==1 [w=suly], fe cluster(sorszam)
  qui outreg using FEFD, se bdec(3) starlev(5) merge ctitle("","FE")
qui reg Droma D$HARDSHIP W5 W6 if $DESCENT==1 [w=suly], cluster(sorszam)
  qui outreg using FEFD, se bdec(3) starlev(5) merge ctitle("","FD")
qui reg Droma D$HARDSHIP W5 W6 $DCONTROLS if $DESCENT==1 [w=suly], cluster(sorszam)
  outreg using FEFD, se bdec(3) starlev(5) merge ctitle("","FD")


*************************************************************************
** SPLIT SAMPLE RESULTS BY DETAILS OF DESCENT
** ONE PARENT W/ ROMA DESCENT; TWO PARENTE MIXED (ONE PARENT W/ ROMA DESCENT AND ONE W/O); TWO PARENTS W/ ROMA DESCENT
** SUMMARY STATISTICS
use temp_bal,replace
global CONTROLS
sum roma $HARDSHIP $CONTROLS [w=suly] if $DESCENT==1 & descent_bothroma==1 , separator(0)
sum roma $HARDSHIP $CONTROLS [w=suly] if $DESCENT==1 & descent_mixed==1 , separator(0)
sum roma $HARDSHIP $CONTROLS [w=suly] if $DESCENT==1 & descent_twoparents==0, separator(0)
*xtsum roma if $DESCENT==1 & descent_bothroma==1  & missing_controls==0
*xtsum roma if $DESCENT==1 & descent_mixed==1 & missing_controls==0
*xtsum roma if $DESCENT==1 & descent_twoparents==0 & missing_controls==0
xtsum roma if $DESCENT==1 & descent_bothroma==1 & hardship==0
xtsum roma if $DESCENT==1 & descent_mixed==1  & hardship==0
xtsum roma if $DESCENT==1 & descent_twoparents==0  & hardship==0
** FE + CONTROLS
qui xtreg roma $HARDSHIP $CONTROLS W4 W5 W6 if $DESCENT==1 & descent_bothroma==1 [w=suly], fe cluster(sorszam)
  qui outreg using FE_detailed_descent, se bdec(3) starlev(5) replace ctitle("","both roma")
qui xtreg roma $HARDSHIP $CONTROLS W4 W5 W6 if $DESCENT==1 & descent_mixed==1 [w=suly], fe cluster(sorszam)
  qui outreg using FE_detailed_descent, se bdec(3) starlev(5) merge ctitle("","mixed")
qui xtreg roma $HARDSHIP $CONTROLS W4 W5 W6 if $DESCENT==1 & descent_twoparents==0 [w=suly], fe cluster(sorszam)
  outreg using FE_detailed_descent, se bdec(3) starlev(5) merge ctitle("","one parent")
  
  
*************************************************************************
** ROBUSTNESS CHECKS
** FE + CONTROLS ONLY

** lags, leads
* one lag
use temp_bal,replace
global CONTROLS
*xtsum roma if $DESCENT==1 & missing_controls==0 & l.hardship!=.
xtsum roma if $DESCENT==1 & l.hardship!=.
qui xtreg roma l(0/1).$HARDSHIP W5 W6 if $DESCENT==1 [w=suly], fe cluster(sorszam)
  qui outreg using FE_laglead, se bdec(3) starlev(5) replace ctitle("","FE lag")
qui xtreg roma l(0/1).$HARDSHIP W5 W6 $CONTROLS if $DESCENT==1 [w=suly], fe cluster(sorszam)
  qui outreg using FE_laglead, se bdec(3) starlev(5) merge ctitle("","FE lag")
* one lead
qui xtreg roma l(0/-1).$HARDSHIP W4 W5 if $DESCENT==1 [w=suly], fe cluster(sorszam)
  qui outreg using FE_laglead, se bdec(3) starlev(5) merge ctitle("","FE lead")
qui xtreg roma l(0/-1).$HARDSHIP W4 W5 $CONTROLS if $DESCENT==1 [w=suly], fe cluster(sorszam)
  outreg using FE_laglead, se bdec(3) starlev(5) merge ctitle("","FE lead")

** unweighted, unbalanced
* unweighted
use temp_bal,replace
global CONTROLS
*xtsum roma if $DESCENT==1 & missing_controls==0
xtsum roma if $DESCENT==1 
qui xtreg roma $HARDSHIP W4 W5 W6 if $DESCENT==1, fe cluster(sorszam)
  qui outreg using FE_unwgtunbal, se bdec(3) starlev(5) replace ctitle("","FE unwgtd")
qui xtreg roma $HARDSHIP W4 W5 W6 $CONTROLS if $DESCENT==1, fe cluster(sorszam)
  qui outreg using FE_unwgtunbal, se bdec(3) starlev(5) merge ctitle("","FE unwgtd")
* unbalanced sample
use temp_unbal,replace
drop if roma==.
drop if $HARDSHIP==.
*xtsum roma if $DESCENT==1 & missing_controls==0
xtsum roma if $DESCENT==1
qui xtreg roma $HARDSHIP W4 W5 W6 if $DESCENT==1 [w=suly], fe cluster(sorszam)
  qui outreg using FE_unwgtunbal, se bdec(3) starlev(5) merge ctitle("","FE unbalanced sample")
qui xtreg roma $HARDSHIP W4 W5 W6 $CONTROLS if $DESCENT==1 [w=suly], fe cluster(sorszam)
  outreg using FE_unwgtunbal, se bdec(3) starlev(5) merge ctitle("","FE unbalanced sample")

** variations on descent
use temp_bal,replace
global CONTROLS
* narrow descent
qui xtreg roma $HARDSHIP W4 W5 W6 $CONTROLS if descent_roma_narrow==1 [w=suly], fe cluster(sorszam)
  qui outreg using FE_narrowbio, se bdec(3) starlev(5) replace ctitle("","FE narrow descent")
* Roma descent from biological parents only
qui xtreg roma $HARDSHIP W4 W5 W6 $CONTROLS if descent_roma_bio==1 [w=suly], fe cluster(sorszam)
  outreg using FE_narrowbio, se bdec(3) starlev(5) merge ctitle("","FE bio descent")
xtsum roma if descent_roma_narrow==1 
xtsum roma if descent_roma_bio==1 
  
** ALTERNATIVE MEASURES OF HARDSHIP
use temp_bal,replace
global CONTROLS
cap gen neg_lninc=-ln(inc_eq_r_corr)
cap gen inc60=inc_eq_r_corr<60000
cap gen inc30=inc_eq_r_corr<30000
*xtsum roma if $DESCENT==1 & missing_controls==0 & hardship_intens~=.
*xtsum roma if $DESCENT==1 & missing_controls==0 & neg_lninc~=.
*xtsum roma if $DESCENT==1 & missing_controls==0 & inc60~=.
*xtsum roma if $DESCENT==1 & missing_controls==0 & inc30~=.
xtsum roma if $DESCENT==1  & hardship_intens~=.
xtsum roma if $DESCENT==1  & neg_lninc~=.
xtsum roma if $DESCENT==1  & inc60~=.
xtsum roma if $DESCENT==1  & inc30~=.
* hardship intensity
qui xtreg roma hardship_intens W4 W5 W6 $CONTROLS if $DESCENT==1 [w=suly], fe cluster(sorszam)
  qui outreg using FE_hardship, se bdec(3) starlev(5) replace ctitle("","h intensity")
* hardship as negative of ln income
qui xtreg roma neg_lninc W4 W5 W6 $CONTROLS if $DESCENT==1 [w=suly], fe cluster(sorszam)
  qui outreg using FE_hardship, se bdec(3) starlev(5) merge ctitle("","neg income")
* hardship as income<50th
qui xtreg roma inc60 W4 W5 W6 $CONTROLS if $DESCENT==1 [w=suly], fe cluster(sorszam)
  qui outreg using FE_hardship, se bdec(3) starlev(5) merge ctitle("","inc50")
* hardship as income<30th
qui xtreg roma inc30 W4 W5 W6 $CONTROLS if $DESCENT==1 [w=suly], fe cluster(sorszam)
  outreg using FE_hardship, se bdec(3) starlev(5) merge ctitle("","inc30")

** SYMMETRY: TURNING ON AND TURNING OFF IDENTIFICATION SEPARATELY
use temp_bal,replace
global DCONTROLS
sort sorszam wavenum
cap gen romaon =roma==1 & roma[_n-1]==0 if sorszam==sorszam[_n-1]
cap gen romaoff=roma==0 & roma[_n-1]==1 if sorszam==sorszam[_n-1]
*xtsum romaon if $DESCENT==1 & missing_controls==0 
*xtsum romaoff if $DESCENT==1 & missing_controls==0 
xtsum romaon if $DESCENT==1 
xtsum romaoff if $DESCENT==1
qui reg romaon D$HARDSHIP $DCONTROLS W4 W5 if $DESCENT==1 [w=suly], cluster(sorszam)
  qui outreg using switch_roma_on_off, se bdec(3) starlev(5) replace ctitle("","Roma on")
qui reg romaoff D$HARDSHIP $DCONTROLS W4 W5 if $DESCENT==1 [w=suly], cluster(sorszam)
  outreg using switch_roma_on_off, se bdec(3) starlev(5) merge ctitle("","Roma off")

*****************************
** FE REGRESSIONS ON ROMA IDENTIFICATION AS FIRST VS SECOND CHOICE
use temp_bal,replace
global CONTROLS
*xtsum roma1 if $DESCENT==1 & missing_controls==0 
*xtsum roma2 if $DESCENT==1 & missing_controls==0 
xtsum roma1 if $DESCENT==1 
xtsum roma2 if $DESCENT==1 
qui xtreg roma1 $HARDSHIP W4 W5 W6 $CONTROLS if $DESCENT==1 [w=suly], fe cluster(sorszam)
  qui outreg using FE_romafirstsecond, se bdec(3) starlev(5) replace ctitle("","FE Roma1")
qui xtreg roma2 $HARDSHIP W4 W5 W6 $CONTROLS if $DESCENT==1 [w=suly], fe cluster(sorszam)
  outreg using FE_romafirstsecond, se bdec(3) starlev(5) merge ctitle("","FE Roma2")

*****************************
** FE LOGIT, RE PROBIT
use temp_bal,replace
global CONTROLS
** FE Logit
qui xtlogit roma $HARDSHIP W4 W5 W6 $CONTROLS if $DESCENT==1, fe 
  qui outreg using FElogit_REprobit, se bdec(3) starlev(5) replace
  qui predict p_logit if e(sample)
  qui gen p_1_p_logit=p_logit*(1-p_logit)
  tabstat p_1_p_logit if $DESCENT==1, s(mean n)
  dis 0.182*0.341
  xtsum roma if p_1_p_logit!=.
** Correlated RE Probit
qui foreach x of varlist $HARDSHIP $CONTROLS {
	cap egen mean_`x'=mean(`x'), by(sorszam)
}
qui xtprobit roma $HARDSHIP W4 W5 W6 $CONTROLS mean_* if $DESCENT==1, re
  qui outreg using FElogit_REprobit, se bdec(3) starlev(5) merge
  qui predict bx_prob if e(sample), xb
  qui gen p_prob=normalden(bx)
  tabstat p_prob if $DESCENT==1, s(mean n)
  dis 0.201*0.366
 
*****************************
** FE & FD REGRESSIONS NON ROMA DESCENT
** SUMMARY STATISTICS
use temp_bal,replace
sum roma $HARDSHIP $CONTROLS [w=suly] if $DESCENT==0, separator(0)
sum Droma D$HARDSHIP $DCONTROLS [w=suly] if $DESCENT==0, separator(0)
xtsum roma if $DESCENT==0
xtsum roma if $DESCENT==0 & missing_controls==0
** FE & FD REGRESSIONS
qui xtreg roma $HARDSHIP D$HARDSHIP if $DESCENT==0 [w=suly], fe cluster(sorszam)
  qui outreg using FEFD_noRomadescent, se bdec(3) starlev(5) replace ctitle("","DELETE")
qui xtreg roma $HARDSHIP W4 W5 W6 if $DESCENT==0 [w=suly], fe cluster(sorszam)
  qui outreg using FEFD_noRomadescent, se bdec(3) starlev(5) merge ctitle("","FE")
qui xtreg roma $HARDSHIP W4 W5 W6 $CONTROLS if $DESCENT==0 [w=suly], fe cluster(sorszam)
  qui outreg using FEFD_noRomadescent, se bdec(3) starlev(5) merge ctitle("","FE")
qui reg Droma D$HARDSHIP W5 W6 if $DESCENT==0 [w=suly], cluster(sorszam)
  qui outreg using FEFD_noRomadescent, se bdec(3) starlev(5) merge ctitle("","FD")
qui reg Droma D$HARDSHIP W5 W6 $DCONTROLS if $DESCENT==0 [w=suly], cluster(sorszam)
  outreg using FEFD_noRomadescent, se bdec(3) starlev(5) merge ctitle("","FD")
  
  
 
**********************************************************************
**********************************************************************
* PART II
* ROMA IDENTIFICATION IS RELATED TO ATITUDES
clear
use identification_workfile

global DESCENT descent_roma
*global DESCENT descent_roma_narrow

*****************************
** SAMPLE SELECTION
drop if $DESCENT==.
keep if roma!=.
foreach x of varlist a_* {
	drop if `x'==. & wave=="d"
}
encode wave, gen(wavenum)
xtset sorszam wavenum

sort sorszam wavenum
gen roma_roma      =roma[_n-1]==1 & roma==1 if sorszam==sorszam[_n-1]
gen nonroma_roma   =roma[_n-1]==0 & roma==1 if sorszam==sorszam[_n-1]
gen roma_nonroma   =roma[_n-1]==1 & roma==0 if sorszam==sorszam[_n-1]
gen nonroma_nonroma=roma[_n-1]==0 & roma==0 if sorszam==sorszam[_n-1]

qui reg a_spendmore roma [w=suly] if $DESCENT==1, robust
 qui outreg using attitudes_roma, se bdec(3) starlev(5) replace
foreach y of varlist a_excludebars-a_criminals {
	qui reg `y' roma [w=suly] if $DESCENT==1, robust
	 outreg using attitudes_roma, se bdec(3) starlev(5) merge
}

qui reg a_spendmore roma l.roma [w=suly] if $DESCENT==1, robust
 qui outreg using attitudes_roma_lag, se bdec(3) starlev(5) replace
foreach y of varlist a_excludebars-a_criminals {
	qui reg `y' roma l.roma [w=suly] if $DESCENT==1, robust
	 outreg using attitudes_roma_lag, se bdec(3) starlev(5) merge
}



global X roma_roma nonroma_roma roma_nonroma 
qui reg a_spendmore $X [w=suly] if $DESCENT==1, robust
 outreg using attitudes_roma_transitions, se bdec(3) starlev(5) replace
foreach y of varlist a_excludebars-a_criminals {
	qui reg `y' $X [w=suly] if $DESCENT==1, robust
	 outreg using attitudes_roma_transitions, se bdec(3) starlev(5) merge
}
